package top.houry.queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.stream.IntStream;

public class ArrayBlockingQueueTest {
    public static void main(String[] args) throws InterruptedException {
        ArrayBlockingQueue<Integer> number = new ArrayBlockingQueue<>(10, true);

        number.add(1);
        number.add(2);
        number.add(3);
        number.add(4);
        number.add(5);
        number.add(6);
        number.add(7);
        number.add(8);
        System.out.println(number.peek());
        System.out.println(number.take());
        System.out.println(number.peek());
        System.out.println(number.peek());
        System.out.println(number.peek());
        IntStream.range(0, 10).forEach(value -> new Thread(() ->{
            System.out.println(Thread.currentThread().getName() + "  " + number.poll());
        }).start());
    }
}
